package org.whut.practice.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.whut.practice.pojo.User;
import org.whut.practice.service.UserService;
import org.whut.practice.utils.Response;

import java.util.HashMap;
import java.util.Map;

@Controller
public class UserController {
    @Autowired
    private UserService userService;

    @ResponseBody
    @GetMapping("/user")
    public Map<String, Object> getUser(@RequestParam(value = "uuid", required = false) String uuid,
                                       @RequestParam(value = "name", required = false) String name) {
        User user = userService.getUser(uuid, name);
        return user != null ? Response.makeOkResponse(user, "Successfully get task data") :
                Response.makeErrorResponse("Failed to get task data");
    }
}
